package com.zmn.uac.client;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.uac.UacException;
import com.zmn.uuc.common.constant.DubboConsts;
import com.zmn.uuc.dubbo.interfaces.user.UserModifyRemoteService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * @title: 个人用户修改Dubbo接口
 * @author:Rananquan
 * @Date:2022/6/9 20:13
 */
@Slf4j
@Component
public class UserModifyClient {

    @DubboReference(version = DubboConsts.INTERFACE_VERSION, check = false)
    UserModifyRemoteService userModifyRemoteService;

    /**
     *  根据用户ID修改昵称
     * @param userId 用户id
     * @param nickName 昵称
     * @return
     */
    public Boolean modifyNickNameByUserId(Long userId,String nickName){
        log.info("根据用户ID修改昵称入参，userId：{}，nickName：{}",userId,nickName);
        ResponseDTO<Boolean> modifyResponse = userModifyRemoteService.modifyNickNameByUserId(userId, nickName);
        if(!modifyResponse.isSuccess()){
            log.error("根据用户ID修改昵称请求失败，失败原因：{}",modifyResponse.getMessage());
            throw new UacException(modifyResponse.getMessage());
        }

        Boolean modifyStatus = modifyResponse.getData();
        log.info("根据用户ID修改昵称返回response：{}",modifyStatus);

        return modifyStatus;
    }


    /**
     * 根据用户ID修改头像
     * @param userId 用户id
     * @param avatarSrc 头像地址
     * @return
     */
    public Boolean modifyAvatarSrcByUserId(Long userId,String avatarSrc){
        log.info("根据用户ID修改头像入参，userId：{}，avatarSrc：{}",userId,avatarSrc);
        ResponseDTO<Boolean> modifyResponse = userModifyRemoteService.modifyAvatarSrcByUserId(userId, avatarSrc);
        if(!modifyResponse.isSuccess()){
            log.error("根据用户ID修改头像请求失败，失败原因：{}",modifyResponse.getMessage());
            throw new UacException(modifyResponse.getMessage());
        }

        Boolean modifyStatus = modifyResponse.getData();
        log.info("根据用户ID修改头像返回response：{}",modifyResponse);

        return modifyStatus;
    }
}
